<?php
/**
 * 会员控制器
 * Created by Forever.
 * User: Forever
 * Date: 2018/10/03
 * Time: 上午 10:39
 */
namespace app\pay\controller;
use think\Controller;
use think\Request;
use \think\Db;
use think\Validate;
class Payreturn extends Base{
	public function _initialize() {
	  parent::_initialize ();
	}

     //获取微信配置信息
    public function get_options($type=0,$web_id=0)
    {
        $options = [];
        $weixinInfo =  Db::connect(config('database.db_config3'))->name('AppWechatCustomer')->where(['web_id'=>$web_id,'pay_status'=>1,'type'=>$type])->field('number,pay_key,app_id,bind_website,key_path')->find();
        //halt($weixinInfo);
        if(!empty($weixinInfo))
        {
            $options =[
                'app_id' => $weixinInfo["app_id"],
                'payment' => [
                    'merchant_id' => $weixinInfo["number"],
                    'key' => $weixinInfo["pay_key"],
                    'cert_path' => $weixinInfo["key_path"],
                    'key_path' => $weixinInfo["key_path"],
                    'notify_url' => $weixinInfo["bind_website"],
                ],
            ];
        }
        return $options;
    }


    //产品订单--微信支付回调
    public function pro_wx_return(){
        //加入参数，调用参数
        $web_type = input('param.web_type');
        // $test['test'] = web_type;
        // db('Test')->insert($test);
        $web_type_arr = explode("_",$web_type);
        $options = $this->get_options($web_type_arr[1],$web_type_arr[0]);
        $this->easywechat = new Application($options);
        // db('test')->where('id',1)->update(['test'=>'lijiantaotest','create_time'=>time()]);
        $response = $this->easywechat->payment->handleNotify(function($notify, $successful){
            $out_trade_no = $notify->out_trade_no;  //微信返回的商户订单号
            $out_trade_no = strstr($out_trade_no, '-', true);
            $transaction_id = $notify->transaction_id??'';  //微信返回的微信交易号
            $time_end = $notify->time_end??'';  //微信返回的交易时间
            $total_fee = $notify->total_fee;        //微信返回的订单金额
        }



    }

}
